package com.yeping.handle.exception;

import com.yeping.domain.ResponseResult;
import com.yeping.enums.AppHttpCodeEnum;
import com.yeping.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobleExceptionHandle {
    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExceptionHandle(SystemException e){
        //打印异常信息
        log.error("出现了异常！{} ",e);
        //返回给前端
        return ResponseResult.errorResult(e.getCode(),e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHandle(Exception e){
        //打印异常信息
        log.error("出现了异常！{} ",e);
        //返回给前端
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR.getCode(),e.getMessage());
    }
}
